/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aexbanner;

import java.awt.*;
import java.awt.Graphics;
import java.util.*;

/**
 *
 * @author Administrator
 */
public class AexPanel extends javax.swing.JPanel {

    private String toPaintString;
    private Timer animationTimer;
    private int curx;
    private IFonds[] fonds;
    // The object we will use to write with instead of the standard screen graphics 
     Graphics bufferGraphics; 
     // The image that will contain everything that has been drawn on 
     // bufferGraphics. 
     Image offscreen; 
    
    /**
     * Creates new form AexPanel
     */
    public AexPanel() {
        initComponents();
        this.setDoubleBuffered(true);
        curx = 0;
        animationTimer = new Timer();
        animationTimer.schedule(new PaintTimerTask(this), 15,15);
        
         
    }
    
    
    public void paint()
    {
        if (toPaintString != null){
            curx+=1;
            if (curx>this.getWidth())
                curx = 0;
            this.repaint();
        }
    }
    
    public void setPaintString(String s)
    {
        toPaintString = s;        
    }
    
    public void setFondsen(IFonds[] fondsen){
       
          this.fonds = fondsen;
        
    }
    
    @Override
    public void paintComponent(Graphics g){
        
        
        if (toPaintString != null){
         
            g.clearRect(0, 0, g.getClipBounds().width, g.getClipBounds().height);
            g.setFont(new Font("Arial",Font.BOLD, 40));
        g.drawString(toPaintString, curx, 40);
        FontMetrics fm = g.getFontMetrics();
        int width = fm.stringWidth(toPaintString);
        g.drawString(toPaintString, curx-width, 40);
     
        
        }
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    class PaintTimerTask extends TimerTask
    {
        private AexPanel panel;
        public PaintTimerTask(AexPanel panel){
            this.panel = panel;
        }
        @Override
        public void run(){
            panel.paint();
        }
    }
}
